package com.pg.controller;

import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pg.entity.EipTemp;
import com.pg.service.EipTempService;

/**
 * 订单临时数据
 *
 * @Description: eip_temp
 * @Author: likl
 * @Date: 2020-07-28
 * @Version: V1.0
 */
@RestController
@RequestMapping("/pg/eipTemp")
public class EipTempController extends JeecgController<EipTemp, EipTempService> {

    @Autowired
    private EipTempService eipTempService;

    /**
     * 添加 订单临时数据
     *
     * @param eipTemp 订单临时数据
     * @return 是否成功
     */
    @ApiOperation("添加 订单临时数据")
    @AutoLog(value = "添加 订单临时数据")
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody EipTemp eipTemp) {
        eipTempService.save(eipTemp);
        return Result.ok("添加成功！");
    }

    /**
     * 编辑 订单临时数据
     *
     * @param eipTemp 订单临时数据
     * @return 是否成功
     */
    @ApiOperation("编辑 订单临时数据")
    @AutoLog(value = "编辑 订单临时数据")
    @PutMapping(value = "/edit")
    public Result<?> edit(@RequestBody EipTemp eipTemp) {
        eipTempService.updateById(eipTemp);
        return Result.ok("编辑成功!");
    }

    /**
     * 通过id删除 订单临时数据
     *
     * @param id 全库唯一码
     * @return 是否成功
     */
    @ApiOperation("通过id删除 订单临时数据")
    @AutoLog(value = "通过id删除 订单临时数据")
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
        eipTempService.removeById(id);
        return Result.ok("删除成功!");
    }

    /**
     * 批量删除 订单临时数据
     *
     * @param ids 全库唯一码集合
     * @return 是否成功
     */
    @ApiOperation("批量删除 订单临时数据")
    @AutoLog(value = "批量删除 订单临时数据")
    @DeleteMapping(value = "/deleteBatch")
    public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.eipTempService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.ok("批量删除成功!");
    }

    /**
     * 通过id查询 订单临时数据
     *
     * @param id 数据库唯一标识
     * @return 订单临时数据
     */
    @ApiOperation("通过id查询 订单临时数据")
    @AutoLog(value = "通过id查询 订单临时数据")
    @GetMapping(value = "/queryById")
    public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
        EipTemp eipTemp = eipTempService.getById(id);
        if (eipTemp == null) {
            return Result.error("未找到对应数据");
        }
        return Result.ok(eipTemp);
    }

    /**
     * 分页列表查询 订单临时数据
     *
     * @param eipTemp  订单临时数据
     * @param pageNo   起始页
     * @param pageSize 每页页数
     * @param req      参数
     * @return 订单临时数据
     */
    @ApiOperation("分页列表查询 订单临时数据")
    @AutoLog(value = "分页列表查询 订单临时数据")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(EipTemp eipTemp,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<EipTemp> queryWrapper = QueryGenerator.initQueryWrapper(eipTemp, req.getParameterMap());
        Page<EipTemp> page = new Page<EipTemp>(pageNo, pageSize);
        IPage<EipTemp> pageList = eipTempService.page(page, queryWrapper);
        return Result.ok(pageList);
    }

    /**
     * 通过excel导入数据 订单临时数据
     *
     * @param request  请求
     * @param response 响应
     * @return 订单临时数据
     */
    @ApiOperation("通过excel导入数据 订单临时数据")
    @AutoLog(value = "通过excel导入数据 订单临时数据")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, EipTemp.class);
    }

    /**
     * 导出excel 订单临时数据
     *
     * @param request 请求
     * @param eipTemp 订单临时数据
     */
    @ApiOperation("导出excel 订单临时数据")
    @AutoLog(value = "导出excel 订单临时数据")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, EipTemp eipTemp) {
        return super.exportXls(request, eipTemp, EipTemp.class, "eip_temp");
    }

}
